using UnityEngine;

public class BulletShell : MonoBehaviour
{
	public Rigidbody2D rb;

	public SpriteRenderer sr;

	public BoxCollider2D bc;

	public AudioSource audioSource;

	public AudioClip[] audioClips;

	public Vector2 outForce = new Vector2(-0.005f, 0.002f);

	public int colliderLayer = 2;

	private bool onGround;

	private void Awake()
	{
		Object.Destroy(base.gameObject, 10f);
	}

	private void Start()
	{
		rb.AddRelativeForce(outForce * Random.Range(0.8f, 1.2f));
		rb.rotation = Random.Range(0, -20);
		rb.AddTorque(Random.Range(-0.0001f, -0.0003f));
	}

	public void Sleep()
	{
		Object.Destroy(rb);
		Object.Destroy(bc);
		Object.Destroy(audioSource, 2f);
		Object.Destroy(this);
	}

	private void OnCollisionEnter2D(Collision2D collision)
	{
		if (!onGround)
		{
			audioSource.PlayOneShot(audioClips[Random.Range(0, audioClips.Length)]);
			sr.sortingOrder = -20;
			Invoke("Sleep", 0.2f);
		}
		onGround = true;
	}
}
